Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

886
Views
BigQuery: 404 "Table is truncated." when insert right after truncate

I truncate my table by executing a queryJob described here: https://cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries

"truncate table " + PROJECT_ID + "." + datasetName + "." + tableName;

i wait until the job finishes via

queryJob = queryJob.waitFor();

Truncate works fine.

Anyway, if i do an insert right after the truncate operation via

InsertAllResponse response = table.insert(rows);

it results in a

com.google.cloud.bigquery.BigQueryException: Table is truncated.

with following log:

Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
    POST https://www.googleapis.com/bigquery/v2/projects/[MYPROJECTID]/datasets/[MYDATASET]/tables/[MYTABLE]/insertAll?prettyPrint=false
    {
      "code" : 404,
      "errors" : [ {
        "domain" : "global",
        "message" : "Table is truncated.",
        "reason" : "notFound"
      } ],
      "message" : "Table is truncated.",
      "status" : "NOT_FOUND"
    }

Sometimes i have even to wait more than 5 Minutes between truncate and insert.

I would like to check if my table is still in the state "Table is truncated." periodically until this state is gone.

How can i request bigquery api in order to check if the table is ready for inserts?

How can i request bigquery api for get the status of the table?

Edit

example for reproduce can be found here

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If a table is truncated while the streaming pipeline is still going on or performing a streaming insertion on a recently truncated table, you could receive some errors like mentioned in the question (Table is truncated), that's expected behavior. The metadata consistency mode for the InsertAll (very high QPS API) is eventually consistent, this means that when using the InsertAll API, it may get delayed table metadata and returns the failure like table truncated. The typical way to resolve this issue is to back-off and retry.

Currently, there is no option in the BigQuery API to check if the table is in truncated state or not.

over 4 years ago · Santiago Trujillo Report

0

Unfortunately the api does not (yet?) provide an endpoint to check the truncated state of the table.

In order to avoid this issue, one can use a load job via gc storage.

It looks like the load job respects this state, as i have no issues with truncate/load multiple times in a row.

public void load(String datasetName, String tableName, String sourceUri) throws InterruptedException {
    Table table = getTable(datasetName, tableName);

    Job job = table.load(FormatOptions.json(), sourceUri);
    // Wait for the job to complete

    Job completedJob = job.waitFor(RetryOption.initialRetryDelay(Duration.ofSeconds(1)),
            RetryOption.totalTimeout(Duration.ofMinutes(3)));
    if (completedJob != null && completedJob.getStatus().getError() == null) {
        // Job completed successfully
    } else {
        // Handle error case
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!